package com.lxs.legou.order.client;

import com.lxs.legou.item.api.SpuApi;
import com.lxs.legou.item.po.Spu;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;

import java.util.List;

/**
 * @Auther: Mcb
 * @Date: 2022/1/9 21:49
 * @Description: 使用fallbackFactory追踪熔断错误信息
 */
@FeignClient(name = "item-service" ,fallbackFactory = SpuClient.SpuFallbackFactory.class)
public interface SpuClient extends SpuApi {

    class SpuFallbackFactory implements FallbackFactory<SpuClient> {

        Logger logger = LoggerFactory.getLogger(SpuFallbackFactory.class);

        @Override
        public SpuClient create(Throwable throwable) {
            throwable.printStackTrace();
            logger.error(throwable.getMessage());

            return new SpuClient() {
                @Override
                public List<Spu> selectAll() {
                    logger.error("fallbackFactory--SpuClient.selectAll");
                    return null;
                }

                @Override
                public Spu edit(Long id) {
                    logger.error("fallbackFactory--SpuClient.edit");
                    return null;
                }
            };
        }
    }

}
